package cn.zhb.backend.core.entity;

import cn.zhb.backend.core.enumerate.UserRole;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.apache.ibatis.type.EnumTypeHandler;

import javax.persistence.*;
import java.util.List;

/***
 *@Description
 *@Author ZHB
 *@Create 2025/7/3 下午2:30
 **/
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Table(name = "sys_user", indexes = {
        @Index(name = "idx_account", columnList = "account")
})
@TableName("sys_user")
@ApiModel(description = "用户")
public class User extends  BaseEntity{

    @ApiModelProperty("账户")
    @Column(name = "account", nullable = false)
    @TableField(value = "account")
    private String account;

    @ApiModelProperty("密码")
    @Column(name = "password", nullable = false)
    @TableField(value = "password")
    private String password;

    @ApiModelProperty("用户名")
    @Column(name = "username", nullable = false)
    @TableField(value = "username")
    private String username;

    @ApiModelProperty("电话")
    @Column(name = "phone")
    @TableField(value = "phone")
    private String phone;

    @ApiModelProperty("角色")
    @Column(name = "role", nullable = false)
    @Enumerated(EnumType.STRING)
    @TableField(value = "role", typeHandler = EnumTypeHandler.class)
    private UserRole role;

    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
    @TableField(exist = false)
    private List<UserQuestionRecord> userQuestionRecordList;

}
